import os
import pandas as pd

file_path = r"D:\python charm\01\可视化\销售看板参考\第四章 销售看板参考.xlsx"
sheet_name = "成本明细"

data = pd.read_excel(file_path, sheet_name=sheet_name)

monthly_data = {}

for month in range(1, 13):
    month_str = f"{month}月"
    monthly_data[f'dh{month}'] = data[data['月份_成本'] == month_str]

# 目标目录
output_dir = r"D:\python charm\01\可视化\销售看板参考"

for name, df in monthly_data.items():
    file_name = os.path.join(output_dir, f"成本明细_{name}.xlsx")
    df.to_excel(file_name, index=False)
    print(f"已导出 {file_name}")